

from config import TestCaseManager
from threading import Thread
from data_center import DataCenter

class EchoServer(Thread):
	def __init__(self,config,publisher,echo_server_map):
		super(EchoServer, self).__init__()

		ip_list = config["ip_list"]
		port_list = config["port_list"]

		self.publisher_ = publisher
		self.test_case_manager_ = TestCaseManager([echo_server_map])
		default_mt_id = self.test_case_manager_.getDefaultMapTableID()
		arm_map_table = self.test_case_manager_.getTestCaseForArm(default_mt_id)
		power_map_table = self.test_case_manager_.getTestCaseForPower(default_mt_id)
		dut_map_table = self.test_case_manager_.getTestCaseForDut(default_mt_id)
		base_id_regex = self.test_case_manager_.getBaseIDRegex(default_mt_id)

		self.dc_ = 	DataCenter(ip_list,port_list)
		self.dc_.setMapTable(arm_map_table,power_map_table,dut_map_table,base_id_regex)
		self.setDaemon(True) 


	def run(self):
		"""Launch echo server, then dead."""
		print("Launch echo server.........")
		self.dc_.launchServer()
		print("Launch echo server success.")
